package it.eng.ws.test.automata;

import it.eng.ws.test.logging.LoggingSample;

import java.util.HashMap;

import org.apache.log4j.Logger;

import cern.jet.random.Poisson;
import cern.jet.random.engine.MersenneTwister;

public class StateLink {

	private float likelyhood = -1;
	private TransitionDelayType delayType = null;
	private long meanTransitionDelay = -1;
	private String targetState = null;
	private String label=null;


	private HashMap<Thread, Poisson> randomGenerators = null;
	private static Logger l = null;
	
	public StateLink(){
		randomGenerators = new HashMap<Thread, Poisson>();
		if (l == null)
			l = LoggingSample.getLogger(it.eng.ws.test.automata.StateLink.class);
	}
	
	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}
	
	public float getLikelyhood() {
		return likelyhood;
	}
	
	public void setLikelyhood(float likelyhood) {
		this.likelyhood = likelyhood;
	}
	
	public long getMeanTransitionDelay() {
		return meanTransitionDelay;
	}
	
	public void setMeanTransitionDelay(long meanTransitionDelay) {
		this.meanTransitionDelay = meanTransitionDelay;
	}
	
	public TransitionDelayType getDelayType() {
		return delayType;
	}

	public void setDelayType(TransitionDelayType delayType) {
		this.delayType = delayType;
	}

	public String getTargetState() {
		return targetState;
	}
	
	public void setTargetState(String targetState) {
		this.targetState = targetState;
	}
	
	public synchronized Poisson getPDRandomGenerator(){
		Poisson poisson = randomGenerators.get(Thread.currentThread());
		
		if (poisson==null){
			poisson = new Poisson(meanTransitionDelay,new MersenneTwister(Thread.currentThread().hashCode()*this.hashCode()));
			randomGenerators.put(Thread.currentThread(), poisson);
		}
		
		return poisson;
	}
	
}
